package com.xsj.controller;

import com.xsj.dto.ResponseDto;
import com.xsj.service.LoginService;
import com.xsj.vo.UserVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "LoginController")
@CrossOrigin
@RestController
@RequestMapping({"/login"})
public class LoginController {
    @Autowired
    private LoginService loginService;


    @Operation(summary = "登录", description = "进行登录")
    @PostMapping({"/index"})
    public ResponseDto aIndex(@RequestBody LoginRequest request) {
        return this.loginService.login(request.getAccount(), request.getPassword(), request.getInputCaptcha(), request.getKey());
    }


    @PostMapping("/register")
    public ResponseDto register(@RequestBody UserVO userVO) {
        return ResponseDto.success(loginService.register(userVO));
    }

    static class LoginRequest {
        private String account;
        private String password;
        private String inputCaptcha;
        private String key;

        LoginRequest() {
        }

        public String getAccount() {
            return this.account;
        }

        public void setAccount(String account) {
            this.account = account;
        }

        public String getKey() {
            return this.key;
        }

        public String getPassword() {
            return this.password;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public String getInputCaptcha() {
            return this.inputCaptcha;
        }

        public void setInputCaptcha(String inputCaptcha) {
            this.inputCaptcha = inputCaptcha;
        }
    }
}
